<?php


namespace api\app\controller;


use api\app\model\UserModel;
use api\app\validate\UserValidate;
use cmf\controller\RestBaseController;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\Request;

class UserController extends RestBaseController
{

    //查询用户数据
    public function userList(Request $request)
    {
        //中间件token传值
        $id = $request->token;
        $data = UserModel::field('id,image,name,mobile')->find($id);
        if (!$data){
            $this->error('无用户');
        }
        $this->success('查询成功',[
            'user' => $data
        ]);

    }
    //修改功能
    public function edit(Request $request)
    {
        //中间件token传值
        $id = $request->token;

        $data = input('post.');
       if (!$data){
           $this->error('参数错误');
       }
        $validate = new UserValidate();
        $res = $validate->scene('edit')->check($data);
        if (!$res){
            $this->error($validate->getError());
        }

        $user = UserModel::find($id);
        $user->image = $data['image'];
        $user-> name = $data['name'];
        $user->mobile = $data['mobile'];
        $user->update_time = time();
        if ($user->save()){
            $this->success('保存成功');
        }else{
            $this->error('保存失败');
        }

    }


}